package com.landeb.shop.huo.view;

import android.content.Context;
import android.support.design.widget.BottomSheetDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.landeb.shop.R;

/**
 * Created by blade on 2017/7/22.
 */

public class SkuView<T extends BaseQuickAdapter> {

//    sku各项需要的默认值

//    private static final String IMG_URL = "";
//    private static final String GOOD_TITLE = "";
//    private static final String GOOD_DESC = "";
//    private static final String GOOD_PRICE = "";

    //    dialog
    private BottomSheetDialog mDialog;

    // sku构造所输入的值
    private Context mContext;
    private String mImgUrl, mGoodTitle, mGoodDesc, mGoodPrice;
    private T mT;
    private int mAmount;
    private View.OnClickListener mBuyNowListener, mAddToCartListener;

    public SkuView(Context context, String imgUrl, String goodTitle, String goodDesc, String goodPrice, T t, int amount, View.OnClickListener buyNowListener, View.OnClickListener addToCartListener) {
        mContext = context;
        mImgUrl = imgUrl;
        mGoodTitle = goodTitle;
        mGoodDesc = goodDesc;
        mGoodPrice = goodPrice;
        mT = t;
        mAmount = amount;
        mBuyNowListener = buyNowListener;
        mAddToCartListener = addToCartListener;

        mDialog = new BottomSheetDialog(mContext);



        mDialog.setContentView(initViews());

    }



    private View initViews() {

        View dialogView = LayoutInflater.from(mContext).inflate(R.layout.bottom_sku_layout, null);

        ImageView dialogIv = (ImageView) dialogView.findViewById(R.id.iv_img_bottom_sku);
        TextView dialogTvTitle = (TextView) dialogView.findViewById(R.id.tv_title_bottom_sku);
        TextView dialogTvDesc = (TextView) dialogView.findViewById(R.id.tv_desc_bottom_sku);
        TextView dialogTvPrice = (TextView) dialogView.findViewById(R.id.tv_price_bottom_sku);

        RecyclerView dialogRv = (RecyclerView) dialogView.findViewById(R.id.rv_bottom_sku);

        Button btnIncrease = (Button) dialogView.findViewById(R.id.btn_increase_bottom_sku);
        Button btnDecrease = (Button) dialogView.findViewById(R.id.btn_Decrease_bottom_sku);
        final TextView dialogTvAmount = (TextView) dialogView.findViewById(R.id.tv_amount_bottom_sku);

        Button btnBuyNow = (Button) dialogView.findViewById(R.id.btn_buyNow_bottom_sku);
        Button btnAddToCart = (Button) dialogView.findViewById(R.id.btn_addToCart_bottom_sku);

        Glide.with(mContext).load(mImgUrl).into(dialogIv);
        dialogTvTitle.setText(mGoodTitle);
        dialogTvDesc.setText(mGoodDesc);
        dialogTvPrice.setText(mGoodPrice);

        dialogRv.setLayoutManager(new LinearLayoutManager(mContext));
        dialogRv.setAdapter(mT);

        dialogTvAmount.setText(mAmount + "");
        btnIncrease.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mAmount++;
                dialogTvAmount.setText(mAmount + "");

            }
        });
        btnDecrease.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mAmount--;
                dialogTvAmount.setText(mAmount + "");

            }
        });

        btnBuyNow.setOnClickListener(mBuyNowListener);
        btnAddToCart.setOnClickListener(mAddToCartListener);

        return dialogView;
    }

    public void show() {
        mDialog.show();
    }

    public void dismiss() {
        mDialog.dismiss();
    }
}
